package cn.iotab.iotkit.transport.api.access.model.custom.firmware;

import cn.iotab.iotkit.transport.api.access.model.message.CommonDeviceMessageReply;
import cn.iotab.iotkit.transport.api.access.model.message.OriginMessageReply;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

/**
 * 拉取固件信息响应
 *
 * @author zhouhao
 * @since 1.0.3
 */
@Getter
@Setter
public class RequestFirmwareMessageReply extends CommonDeviceMessageReply{

    /**
     * 固件下载地址
     */
    private String url;

    /**
     * 固件版本
     */
    private String version;

    /**
     * 其他参数
     */
    private Map<String, Object> params;

    /**
     * 签名
     */
    private String sign;

    /**
     * 签名方式,md5,sha256
     */
    private String signMethod;

    /**
     * 固件ID
     *
     * @since 1.1.4
     */
    private String firmwareId;

    /**
     * 固件大小
     *
     * @since 1.1.5
     */
    private long size;

    @Override
    public void fromOriginMessageReply(String productKey, String deviceId, OriginMessageReply messageReply) {
        throw new UnsupportedOperationException("unsupported operation for not support device RequestFirmwareMessageReply to platform");
    }

    @Override
    public OriginMessageReply toOriginMessageReply() {
        JSONObject object = new JSONObject();
        object.put("url", this.url);
        object.put("version", this.version);
        object.put("params", this.params);
        object.put("sign", this.sign);
        object.put("signMethod", this.signMethod);
        object.put("firmwareId", this.firmwareId);
        object.put("size", this.size);
        //
        setData(object);
        return super.toOriginMessageReply();
    }
}
